<?php

/**
 * RemoveShift Function
 *
 * Remove an existing shift.
 *
 * @author Max Sibbald <maxsibbald@gmail.com>
 */
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';
include_once 'UTDBGlobal.php';

/**
 * @param $authUser string
 * @param $authUserPass string
 * @param $roleID string
 * @param $dateID string
 * @param $empID string
 * @return array
 */
function removeShift($authUser, $authUserPass, $roleID, $dateID, $empID) {
   global $dbaddress;
   global $dbuser;
   global $dbpassword;
   global $dbdatabasename;

   if (checkAuthentication($authUser, $authUserPass) != true) {
      return array(ErrorCode::authFailRead);
   }

   $conn = mysqli_connect($dbaddress, $dbuser, $dbpassword, $dbdatabasename);
   if (!$conn) {
      die('Could not connect: ' . mysql_error());
      return array(ErrorCode::sysError);
   }

   $sql = "DELETE FROM proposedchange WHERE roleID=$roleID AND dateID=$dateID AND empID=$empID";
   mysqli_query($conn, $sql);

   $sql = "DELETE FROM roledate WHERE roleID=$roleID AND dateID=$dateID AND empID=$empID";
   if (mysqli_query($conn, $sql)) {
      mysqli_close($conn);
      return array(ErrorCode::successDelete);
   } else {
      mysqli_close($conn);
      return array(ErrorCode::failDelete);
   }
}

?>